package com.itheima.tlias.tliasweb.config;

import com.itheima.tlias.tliasweb.interceptor.LoginCheckInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

//    @Autowired
//    DemoInterceptor demoInterceptor;

    @Autowired
    private LoginCheckInterceptor loginCheckInterceptor;
    /**
     * 注册拦截器
     * */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加DemoInterceptor，拦截路径是/** 也就是所有路径
//        registry.addInterceptor(demoInterceptor).addPathPatterns("/**");
//        registry.addInterceptor(new AbcInterceptor()).addPathPatterns("/**");
//        registry.addInterceptor(new LoginInterceptor())
//                .addPathPatterns("/**")  //要拦截的路径
//                .excludePathPatterns("/login");// 不拦截的路径
        registry.addInterceptor(loginCheckInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/upload")
                .excludePathPatterns("/*.html");
    }
}
